package kr.co.boogui.helper;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class EncodingFilter implements Filter {

	 private FilterConfig m_config = null;
	 private String m_encoding = "euc-kr";

	 public void init(FilterConfig config) throws ServletException {
	  m_config   = config;
	  m_encoding = config.getInitParameter("encoding");
	  System.out.println("EncodingFilter.init().... " + m_encoding);
	 }

	 public  void doFilter(ServletRequest srequest, ServletResponse  sresponse, FilterChain chain)
	  throws IOException, ServletException {

	  HttpServletRequest request = (HttpServletRequest)srequest;
	  request.setCharacterEncoding(m_encoding);
	  System.out.println("EncodingFilter.doFilter().... " + request.getRequestURI()+":"+request.getCharacterEncoding());
	  // move on to the next
	  chain.doFilter(srequest, sresponse);
	 }

	 public void destroy() {
	  m_config = null;
	  m_encoding = null;
	 }
	}  

